<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>其他合同补充协议</title>
</head>
<script type="text/html" id="layui-row"  >
    <div class="layui-row" id="{0}" >
        <div class="contract-box" >
            <div class="contract-money">
                <table class="layui-table">
                    <colgroup>
                        <col width="90">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="150">
                    </colgroup>
                    <thead>
                    <tr>
                        <td>子项名称<input type="hidden" value="{1}"  name="subNames"  class="subNames" /></td>
                        <td class=tg-c >{1}</td>                        
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
						<td class=tg-c ><button type="button" class="layui-btn layui-btn-sm del-layui-row" title="删除子项"  ><i class="layui-icon">&#xe640;</i></button></td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <th>序号</th>
                        <th>费用类型</th>
                        <th>对内合同金额（元）</th>
                        <th>对外合同金额（元）</th>
                        <th>前期已录金额（元）</th>
 						<th>开累已录金额（元）</th>
                        <th>对外合同剩余金额（元）</th>
						<th></th>
                    </tr>
                    </tbody>
                    <tbody >
                    <tr id="{0}Row-1" level=1 >
                        <td><span class="label" >1</span><input type="hidden" value="1" name="orderIdxs" /><input type="hidden" value="{0}" name="contractSubIds" /></td>
                        <td  class=tg-c  ><b>{2}</b><input type="hidden" value="1" name="feeTypes" /><input type="hidden" value="-1" name="feeSmallTypes" /><input type="hidden" value="{1}"  name="itemNameSub"  class="itemNameSub" /><input type="hidden" value="{2}" name="typeNames" class="typeNames" /></td>
                        <td><input type="text" name="outOrInnerAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input incontractfee" /></td>
  						<td><input type="text" name="outCotAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input outcontractfee" /></td>
                        <td><input type="text" name="beforeAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input prevrecordfee" /></td>
 						<td><input type="text" name="addupAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input currprevrecordfee" /></td>
                        <td><input type="text" name="outRestAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input surplusoutcontractfee" /></td>
                        <td class=tg-c ><button type="button" class="layui-btn layui-btn-sm add-new-row" ><i class="layui-icon">&#xe654;</i></td>
                    </tr>
                    <tr id="sub{0}Row-1.1"  level=2 >
                        <td><span class="label" >1.1</span><input type="hidden" value="1.1" name="orderIdxs" /><input type="hidden" value="{0}" name="contractSubIds" /></td>
                        <td  class=tg-c  ><label></label><input type="hidden" value="1" name="feeTypes" /><input type="hidden" value="{1}" name="itemNameSub"  class="itemNameSub" /><input type="hidden" value="1.1" name="feeSmallTypes" /><input type="hidden" value="" name="typeNames"  class="typeNames"  /></td>
                   		<td><input type="text" name="outOrInnerAmounts" maxlength="13" lay-verify="required|floatNumber" autocomplete="off"  class="layui-input decimal incontractfee" /></td>
  						<td><input type="text" name="outCotAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input outcontractfee" /></td>
                        <td><input type="text" name="beforeAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input prevrecordfee" /></td>
 						<td><input type="text" name="addupAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input currprevrecordfee" /></td>
                        <td><input type="text" name="outRestAmounts" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input surplusoutcontractfee" /></td>                       
                        <td class=tg-c ><button type="button" class="layui-btn layui-btn-sm add-sub-row" ><i class="layui-icon">&#xe654;</i></button></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</script>

<!-- 用于原记录带出记录 -->
<script type="text/html" id="layui-row-tr" >
<tr id="{0}" level={1} >
<td><span class="label" >{2}</span><input type="hidden" value="{2}" name="orderIdxs" /><input type="hidden" value="{3}" name="contractSubIds" /></td>
<td><input type="text" readonly style="border:0px" value="{4}" autocomplete="off" class="layui-input typeNames" name="typeNames" />
<input type="hidden" value="{5}" name="feeTypes" class="feeTypes" />
<input type="hidden" value="{6}" name="feeSmallTypes" class="feeSmallTypes" />
<input type="hidden" value="{7}" name="itemNameSub" class="itemNameSub" />
</td>
<td><input type="text" name="outOrInnerAmounts" value="{8}" lay-verify="required|floatNumber" maxlength="13" autocomplete="off" class="layui-input decimal incontractfee" /></td>
<td><input type="text" name="outCotAmounts" value="{9}" readonly style="border:0px" class="layui-input  outcontractfee" /></td>
<td><input type="text" name="beforeAmounts" value="{10}" readonly style="border:0px" class="layui-input  prevrecordfee" /></td>
<td><input type="text" name="addupAmounts" value="{11}" readonly style="border:0px" class="layui-input  currprevrecordfee" /></td>
<td><input type="text" name="outRestAmounts" value="{12}" readonly style="border:0px" class="layui-input  surplusoutcontractfee" /></td>
<td class=tg-c ><button type="button" class="layui-btn layui-btn-sm add-sub-row" ><i class="layui-icon">&#xe654;</i></button></td>
</tr>
</script>
<!-- 用于二级新增三级 -->
<script type="text/html" id="layui-row-tr-add" >
<tr id="{0}" level={1} >
<td><span class="label" >{2}</span><input type="hidden" value="{2}" name="orderIdxs" /><input type="hidden" value="{3}" name="contractSubIds" /></td>
<td><input type="text" lay-verify="required" maxlength="50" value="{4}" autocomplete="off" class="layui-input typeNames" name="typeNames" />
<input type="hidden" value="{5}" name="feeTypes" class="feeTypes" />
<input type="hidden" value="{6}" name="feeSmallTypes" class="feeSmallTypes" />
<input type="hidden" value="{7}" name="itemNameSub" class="itemNameSub" />
</td>
<td><input type="text" name="outOrInnerAmounts" value="{8}" lay-verify="required|floatNumber" maxlength="13" autocomplete="off" class="layui-input decimal incontractfee" /></td>
<td><input type="hidden" name="outCotAmounts" value="{9}" class="layui-input  outcontractfee" /></td>
<td><input type="hidden" name="beforeAmounts" value="{10}" class="layui-input  prevrecordfee" /></td>
<td><input type="hidden" name="addupAmounts" value="{11}" class="layui-input  currprevrecordfee" /></td>
<td><input type="hidden" name="outRestAmounts" value="{12}" class="layui-input  surplusoutcontractfee" /></td>
<td class=tg-c ><button type="button" class="layui-btn layui-btn-sm del-sub-row" ><i class="layui-icon">&#xe640;</i></button></td>
</tr>
</script>

<script type="text/html" id="list-mode-tr" >
<tr id="LISTMODERow-{0}"  > 
<td><span class="label" >{0}</span><input type="hidden" value="{0}" name="showIdxLists" /></td> 
<td><input type="text" value="{1}" name="subNameLists" lay-verify="required" autocomplete="off" class="layui-input  subItemListName" /></td>
<td><input type="text" value="{2}" name="subUnitLists" lay-verify="required" autocomplete="off" class="layui-input  measurementUnit" /></td>
<td><input type="text" value="{3}" name="cotNumLists" lay-verify="required|floatNumber" maxlength="10" autocomplete="off" class="layui-input decimal contractsNumber" /></td> 
<td><input type="text" value="{4}" name="cotUnitPriceLists" lay-verify="required|floatNumber" maxlength="13" autocomplete="off" class="layui-input decimal contractPrice" /></td> 
<td><input type="text" value="{5}" name="cotSumPriceLists" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input decimal sumPrice" /></td> 
<td class="tg-c" > 
<button type="button" class="layui-btn layui-btn-sm del-row" ><i class="layui-icon">&#xe640;</i></button> 														
<button type="button" class="layui-btn layui-btn-sm add-row" ><i class="layui-icon">&#xe654;</i></button>
</td> 						
</tr>
</script>

<script type="text/html" id="payment-node-tr" >
<tr id="PAYMENTNODERow-{0}"  > 
<td>
<span class="label" >{0}</span>
<input type="hidden" value="{0}" name="showIdxNodes" />
</td> 
<td><input type="text" value="{1}" name="nodeNames" lay-verify="required" autocomplete="off" class="layui-input nodeName" /></td> 
<td><input type="text" value="{2}" name="payRates" lay-verify="required|floatNumber" maxlength="6" autocomplete="off" class="layui-input decimal nodePayProportion" /></td> 
<td><input type="text" value="{3}" name="payAmounts" readonly style="border:0px" maxlength="13" lay-verify="required|floatNumber" autocomplete="off" class="layui-input payAmount" /></td> 
<td class="tg-c" >
<button type="button" class="layui-btn layui-btn-sm del-row" ><i class="layui-icon">&#xe640;</i></button> 													
<button type="button" class="layui-btn layui-btn-sm add-row" ><i class="layui-icon">&#xe654;</i></button></td> 							
</tr>
</script>
<style>
.contract-price-info{
 	display:none;
}
.contract-price-info legend{
	text-align:left;
	cursor: default;
	width:175px;
}

.list-title{
	display:block;
	width:342px;
	text-align:right;
	left:55px;
	font-size:.89em;
}

.pos-r{
	position: relative;
}
.pos-a{
	position: absolute;
}

.margin-bot10 {
	margin-bottom: 10px;
}

.margin-lt10 {
	margin-left: 10px;
}

.layui-row+.layui-row {
	margin-top: 10px;
}

.tg-l {
	text-align: left;
}

.tg-c {
	text-align: center;
}

.tg-r {
	text-align: right;
}

.contract-list {
	margin-top: 20px;
}

.contract-box {
	width: 100%;
	min-height: 100px;
}

.contract-money {
	width: 90%;
	margin: 0px auto;
}

.contract-money .layui-table {
	margin: 0;
}

.contract-money th {
	text-align: center;
	height: 38px;
}

.contract-money .label {
	display: block;
	width: 45px !important;
	margin-left: 15px;
}

.fieldset {
	margin-top: 5px;
	margin-bottom: 0px
}

.layui-legend {
	background-color: #5fb878;
	font-size: 15px !important;
	width: 160px;
}

.layui-form-item {
	margin-bottom: 5px;
	clear: both;
	*zoom: 1;
}

.layui-form-label {
	width: 160px;
}

.right {
	float: right;
}

.width106 {
	width: 106px;
}

.bankRow+.bankRow {
	border-top: 1px solid #e0e0e0;
	margin-top: 20px;
	padding-top: 20px;
}
</style>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div style="padding-top: 15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
				<div class="layui-tab layui-tab-brief" >
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend"
									style="text-align: left; cursor: default;" >项目基础信息 ></legend>
								<input type="hidden" name="judge" value="2">
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">申请公司</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrOrgid" value="${bindOrgId}">
											<input type="text" value="${bindOrgName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请部门</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrDeptid" value="${bindDeptId}">
											<input type="text" value="${bindDeptName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >申请人</label>
										<div class="layui-input-inline" >
											<input type="hidden" name="hrStaffApplyid"
												value="${SESSION_KEY_USER_DETAIL.hrStaffId }"> <input type="text" name="staffname" value="${staffName }" readonly="readonly" style="border: 0px" autocomplete="off"
												class="layui-input" >
										</div>
									</div>
								</div>
								<div class="layui-form-item"  >								
									<div class="layui-inline" >
										<label class="layui-form-label">其他合同名称</label>
										<div class="layui-input-inline">
											<input type="hidden" id="contractId" name="otherCotName" value="">
											<select id="add_select_proId" 
												lay-filter="add_select_proId" name="proCodeAndCodes" lay-filter="add_select_proId"
												lay-verify="required" lay-search>
												<option value="">请选择-项目名称</option>
												<c:if test="${not empty otherCotList }">
													<c:forEach items="${otherCotList}" var="otherCot">
														<option value="${otherCot.proCode}_${otherCot.id}_${otherCot.proName}">${otherCot.proName }_${otherCot.otherCotName }
														</option>
													</c:forEach>
												</c:if>
											</select>
										</div>
									</div>																	
									<div class="layui-inline">
										<label class="layui-form-label">项目名称</label>
										<div class="layui-input-inline">
											<input type="text" id="id_proName" name="proName" value="" style="border: 0px;width:220px"
												readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">项目编号</label>
										<div class="layui-input-inline">
											<input type="text" id="id_proCode" name="proCode" value="" style="border: 0px;"
												readonly="readonly" class="layui-input">
										</div>
									</div>									
								</div>
								<div class="layui-form-item"  >		
									<div class="layui-inline">
										<label class="layui-form-label">区域公司</label>
										<div class="layui-input-inline">
											<input type="hidden" id="areaId" name="hrOrgAreaId" value="">
											<input type="text" id="id_regionalCompany"
												value="" readonly="readonly"
												style="border: 0px;width:220px" autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >项目公司</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="compId" name="hrOrgProId" value=""> 
											<input type="text" id="id_projectCompany" value=""
												style="border: 0px;width:220px" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >实施机构</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_ImplementingBody" name="carryOrg" style="border: 0px;width:220px"
												readonly="readonly" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item"  >
									<div class="layui-inline" >
										<label class="layui-form-label" >项目地址</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="sgCityId" name="sgCityId" value="">
											<input type="text" id="id_projectAddress" name="projectAddress" value=""
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >项目负责人</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_projectLeader" name="proLeader" style="border: 0px;"
												readonly="readonly" maxlength="10" lay-verify="required|COC"
												class="layui-input">
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >合同单位名称</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="sgCoopId" name="sgCoopId" value="">
											<input type="text" id="id_contractUnitName"
												style="border: 0px;width:220px" readonly="readonly" lay-verify="required|COC"
												class="layui-input">																						
										</div>
									</div>
								</div>
								<div class="layui-form-item"  >
									<div class="layui-inline" >
										<label class="layui-form-label" >补充合同名称</label>
										<div class="layui-input-inline" >
											<input type="text" class="layui-input" maxlength="100" id="id_supplementaryContractName" name="otherCotSaName" lay-verify="required|COC" autocomplete="off" placeholder="请输入补充合同名称" />
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >补充合同编码</label>
										<div class="layui-input-inline" >
											<input type="text" class="layui-input" maxlength="50" id="id_supplementaryContractCode" name="otherCotSaCode" autocomplete="off" placeholder="请输入补充合同编码" />										
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >补充合同签订日期</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" id="id_supplementaryContractSigningDate"  name="signDate" autocomplete="off" placeholder="补充合同签订日期" />
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" >补充内容说明</label>
									<div class="layui-input-block"  >
										<textarea id="id_supplementaryContentDesc"  placeholder="请输入最多500字" name="saMemo"
											class="layui-textarea" maxlength="500" lay-verify="required"
											style="width: 899px; height: 180px;"></textarea>
									</div>
								</div>		
								<div class="layui-form-item" >									
									<div class="layui-inline" >
										<label class="layui-form-label" >费用类型</label>
										<div class="layui-input-inline" >
											<input type="hidden" id="cotTypeId" name="cotType" value="">
											<input type="text" id="id_feeTypes" style="border: 0px;" readonly="readonly" 
											 class="layui-input">
										</div>
									</div>
								</div>						
							</fieldset>						
							<fieldset class="layui-elem-field layui-field-title fieldset contract-price-info"  >													
								<legend class="layui-btn layui-legend" >项目代付费信息 ></legend>
								<div class="contract-list" >																	
									<div class="contract-box margin-bot10" >
	            						<div class="contract-money">
	                						<table class="layui-table">
							                    <colgroup>
							                        <col width="100"  >
							                        <col width="290"  >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                        <col width="290" >
							                    </colgroup>
												<thead>
													<tr>
														<th></th>
														<th>对内合同金额（元）</th>
														<th>对外合同金额（元）</th>
														<th>前期已录金额（元）</th>
														<th>开累已录金额（元）</th>
														<th>对外合同剩余金额（元）</th>
													</tr>
												</thead>
												<tbody >
													<tr>
													    <td class="tg-r" >合计</td>
														<td><input type="text" value="0" id="incontractfee" name="outOrInnerAmount"  onblur="arabiaToCN(this,1)" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="outcontractfee" name="outCotAmount"  onblur="arabiaToCN(this,1)" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="prevrecordfee"  name="beforeAmount"  onblur="arabiaToCN(this,1)" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="currprevrecordfee" name="addupAmount"  onblur="arabiaToCN(this,1)" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input " /></td>
														<td><input type="text" value="0" id="surplusoutcontractfee" name="outRestAmount"  onblur="arabiaToCN(this,1)" readonly style="border:0px" lay-verify="required|floatNumber" autocomplete="off" class="layui-input " /></td>
													</tr>
								                </tbody>
							                </table>
	                    				</div>
                    				</div> 							
								</div>
							</fieldset>				
							<fieldset class="layui-elem-field layui-field-title fieldset"   >							
								<legend class="layui-btn layui-legend" style="text-align:left;cursor: default;" >费用清单 ></legend>								
									<div class="layui-form-item" >
										<div class="layui-inline" >
											<label class="layui-form-label" >合同总价(元)</label>
											<div class="layui-input-inline">
												<input type="text" readonly style="border:0px"  onblur="arabiaToCN(this,1)" name="totalSum" id="sumListMode" value="0" lay-verify="required|floatNumber" class="layui-input" >
											</div>
										</div>
									</div>																		
									<div class="contract-box " id="list-mode" >
	            						<div class="contract-money"		>
	                						<table class="layui-table"	>
							                    <colgroup>
							                        <col width="90"  >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="200" >
							                    </colgroup>
												<thead>
													<tr>
														<th>序号</th>
														<th>清单名称</th>
														<th>计量单位</th>
														<th>合同数量</th>
														<th>合同单价(元)</th>
														<th>合价(元)</th>
														<th></th>
													</tr>
												</thead>
												<tbody>																																				
								                </tbody>
							                </table>
	                    				</div>
	                    			</div>                                       		                    										
							</fieldset>										
																								
							<fieldset class="layui-elem-field layui-field-title fieldset" id="contractInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor:default;" >合同信息 ></legend>								
								<div class="layui-form-item" >
									<div class="layui-inline">
										<label class="layui-form-label">合同工期(年)</label>
										<div class="layui-input-inline">
											<input type="text" id="id_Contractconstructionperiodyear" name="periodYears"
												onblur="checkValueverifyNumber2(this);"
												lay-verify="required|floatNumber" maxlength="100"
												autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">合同工期(天)</label>
										<div class="layui-input-inline">
											<input type="text" id="id_Contractoperationperiodyear" name="periodDays"
												maxlength="100" lay-verify="required|floatNumber" readonly style="border:0px"
												class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">合同开工日期</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" autocomplete="off"
												id="id_contractCommencementDate" lay-verify="required"
												name="beginBuildDate">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >合同竣工日期</label>
										<div class="layui-input-inline" >
											<input type="text" id="id_contractCompletionDate" name="endBuildDate" readonly style="border:0px"
												lay-verify="required" autocomplete="off" class="layui-input">
										</div>
									</div>

									<div class="layui-inline">
										<label class="layui-form-label" >合同结算模式</label>
										<div class="layui-input-inline" >
											<select id="id_cotSettMode" name="cotSettMode" lay-verify="required">
											</select>
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >乙方完工标准</label>
										<div class="layui-input-inline" >
											<textarea id="id_standardMemo" name="standardMemo"
											class="layui-textarea" maxlength="500" lay-verify="required"
											style="width: 899px; height: 90px;"></textarea>
										</div>
									</div>
								</div>						
							</fieldset>								
							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="comprehensivePlanInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >付款节点 ></legend>	
								<div class="layui-form-item">
									<label class="layui-form-label"   ></label> 
								</div>						
								<div class="contract-box" id="payment-node" >
            						<div class="contract-money"		>
                						<table class="layui-table"	>
							                    <colgroup>
							                        <col width="90"  >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="300" >
							                        <col width="250" >
							                    </colgroup>
												<thead>
													<tr>
														<th>序号</th>
														<th>节点名称</th>
														<th>节点付款比例(%)</th>
														<th>付款金额(元)</th>
														<th></th>
													</tr>
												</thead>
												<tbody>
								                </tbody>
						                </table>
                    				</div>
                    			</div>							
							</fieldset>							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >附件></legend>
								<div style="margin-top: 20px;" >
									<div class="layui-form-item" >
										<label class="layui-form-label" style="width: 350px;">支持pdf、excel、word、图片资料，可上传多个</label>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">政府发函</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="5-upload-more">上传</button>
												<div class="layui-upload-list" id="5-upload-more-list">
												</div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">其他附件</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="4-upload-more">上传</button>
												<div class="layui-upload-list" id="4-upload-more-list">
												</div>
											</div>
										</div>
									</div>
								</div>
							</fieldset>
						</div>
					</div>
				</div>
				<div class="layui-form-item"
					style="position: fixed ! important; right: 30px; bottom: 45%; z-index: 10000;">
					<div class="layui-input-block">
						<button
							class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius"
							type="button" lay-submit lay-filter="addInfo_form_submit"
							id="addInfo_form_submit">
							<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i> 提交
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>
<script type="text/javascript"  >
String.prototype.format = function () {
	var model = arguments;
    return this.replace(/\{(\d+)\}/g, function (s, i) { 
        return !!model[i]?model[i]:'';
    });
}
String.prototype.toInt = function () {
	if(this==''){
		return 0;
	}
	return parseInt(this);
}
String.prototype.toFloat = function () {
	if(this==''){
		return 0;
	}
	return parseFloat(this);
}
Number.prototype.toMoney = function () {
	var m = Math.pow(10, 2);
	return Math.round(this * m) / m;
}
var getPercentage = function(a, b, d) {
	var quotient = Number(b) != 0 ? a / b : 0;
	if (d == true) {
		return setDecimalPlaces((1 - quotient) * 100, 2);
	}
	return setDecimalPlaces(quotient * 100, 2);
}

var setDecimalPlaces = function(f, digit) {
	var m = Math.pow(10, digit);
	return Math.round(f * m) / m;
}		
function parentGroup($, type, id) {
	if(type=="incontractfee"){
		amountParentGroup($, 'incontractfee', id);
		amountParentGroup($, 'prevrecordfee', id);
		countTopRows($, ['incontractfee','outcontractfee','prevrecordfee','currprevrecordfee','surplusoutcontractfee']);				
	}
}
function amountParentGroup($, type, id) {
	var arr = id.split('.');
	if (arr.length == 3 && type=="incontractfee"){
		var item = arr.slice(0, 2);
		var trId = item.join('.');				
		var $tr = $('[id="' + trId + '"]');
		$tr.find('.' + type).val($("tr[id^='" + trId + ".'][level=3]").find('.' + type).inputTotal());
		incontractfee(type,$tr);
	}
	if (arr.length >= 2) {
		var trId = arr[0].replace('sub', '');				
		var $tr = $('[id="' + trId + '"]');
		$tr.find('.' + type).val($("tr[id^='" + arr[0] + ".'][level=2]").find('.' + type).inputTotal());
		incontractfee(type,$tr);
	}
}
function countTopRows($, types) {
	var $contractListLayuiRow = $('.layui-row');
	types.forEach(function(e) {		
		var $total = $('#' + e);
		var total = $contractListLayuiRow.find("tr[id$='Row-1'] input[type=text]." + e).inputTotal();
		$total.val(total);
	});
}
function eightS4() {
    function S4() {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    return (S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4()).toLocaleUpperCase();
}

	var subList = [];
	var proName;
	var proNameid;
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	layui.config({base : '${ctx}/resources/layuiadmin/' //静态资源所在路径
			})
			.extend({
				index : 'lib/index' //主入口模块
			})
			.use([ 'index', 'set', 'upload', 'element', 'laydate' ], function() {
						var $ = layui.$, form = layui.form, element = layui.element, laydate = layui.laydate, upload = layui.upload;
						// 正则校验
						form.verify({
							//验证汉字
						    CHS:[
						    	/^[\u0391-\uFFE5]+$/
						    	,'只能输入汉字'
						  	],
						  	//名字校验
						  	COC: [
								/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
								,'请输入正确的名称'
						  	],
						  	//大于0的正整数
						  	intNumber:[
								/^[1-9]\d*$/
								,'请输入正确的数字'
						  	],
						  	//数字只能有两位小数
						  	floatNumber:[
								/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
								,'请输入正确的数字'
						  	],
						  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
								  		,'请输入正确的号码'
							],
						  	//数字大于0，并只能有两位小数
						  	floatAmount:[
								/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
								//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
								,'请输入正确的数字'
						  	]
						});
						
						uploadRender(5, upload, $);
						uploadRender(4, upload, $);
						
						laydate.render({
							elem : '#id_supplementaryContractSigningDate',
							trigger : 'click'
						});
						
						laydate.render({
							elem : '#id_contractCompletionDate',
							trigger : 'click'
						});
						
						checkValueVerifyBeginBuildDate(laydate, $);
						
						(function($) {
							$.fn.inputTotal = function() {
								var sum = 0;
								this.each(function() {
									var thisNum = $(this);
									var val = !!thisNum.val() ? thisNum.val()
											: 0;
									var num = parseFloat(val);
									sum = setDecimalPlaces(sum + num, 2);
								});
								return sum;
							};
						})($);						
						listModeDataBind($);
						paymentNodeDataBind($);										
						otherCot($);
						form.on('select(add_select_proId)', function(data) {
							var id = data.value;
							proNameid = data.value;
							proName = data.elem.getAttribute('proName');
							if(id==''||id==null){
								layer.msg('请选择项目名称',{icon: 1});
					    		return;
							}else{
								getOtherCotByProId(id);
							}							
						});
												
						var type = $('#id_feeTypes').val(),feeTypeName,$contractPriceInfo = $('.contract-price-info');
						if(type=='32'){
							feeTypeName = '政府代付费';
							$contractPriceInfo.find('legend').text('项目代付费信息 >');
						}
						else if(type=='33'){
							feeTypeName = '项目前期费';
							$contractPriceInfo.find('legend').text('项目前期费信息 >');
						}
						if(!!feeTypeName==true){
							$contractPriceInfo.css('display','block');
						}else{
							$contractPriceInfo.css('display','none');
						}						
						
						form.on('submit(addInfo_form_submit)', function(data) {
							$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
							//提交 Ajax 成功后，静态更新表格中的数据
		                   	
		                   	$.ajax({
		                       	type : 'post',
		            			url : basePath + '/otherCot/save',
		                       	data: $('#addInfo_form').serialize(),
		            			success:function(result){
		            				if(result.success){
		            					layer.closeAll('loading'); //关闭loading
		            					layer.msg('提交单据成功~',{icon: 1});
		            					//两秒后关闭当前页面
		            					setTimeout(function(){
		            						/**
		            						 * 查找父菜单，并刷新
		            						 */
		            						var topDoc = $(window.top.document);
		            						var path = basePath + '/otherCot/list';
		            						// 获取页面名称
		            						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
		            						if(name == '' || name == null){
		            							name = '其他合同补充合同';
		            						}
		            						window.parent.layui.index.openTabsPage(path, name);
		            						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
		            						iframe[0].contentWindow.location.reload(true);
		            						
		            						/**
		            						 * 关闭当前页
		            						 */
		            						var currPath = basePath + '/otherCot/add';
		            						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
		            						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
		            				        }, 2000);
		            				}else{
		            					layer.closeAll('loading'); //关闭loading
		              					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
		            					layer.msg(result.msg,{icon: 7});
		            			  	}
		            			}
		                   	});
						});						
					});
	
	var incontractfee = function(type,$tr){
		if(type=='incontractfee' ){
			var incontractfee = $tr.find(".incontractfee").val().toFloat();
			var $outcontractfee = $tr.find(".outcontractfee"),outcontractfee = $outcontractfee.val().toFloat();
			var $prevrecordfee = $tr.find(".prevrecordfee"),prevrecordfee = $prevrecordfee.val().toFloat();
			var $currprevrecordfee = $tr.find(".currprevrecordfee"),
			currprevrecordfee = prevrecordfee + incontractfee;
			$currprevrecordfee.val(currprevrecordfee.toMoney());					
			
			var $surplusoutcontractfee = $tr.find(".surplusoutcontractfee"),
			surplusoutcontractfee = outcontractfee-currprevrecordfee;
			$surplusoutcontractfee.val(surplusoutcontractfee.toMoney());											
		}
	}
	
	var otherCot = function($){
		var $contractList = $('.contract-list'),
		layuiRowHtml = $('#layui-row').html();	
		$contractList.find(".layui-row").remove();		
		$contractList.on('click','.del-layui-row',function(){
			var $layrow = $(this).parents('.layui-row');	
			if($contractList.find('.layui-row').length==1){
				return layer.msg('至少需保留一个子项', {icon: 0});
			}
			layui.layer.confirm('确定删除子项？', {
						icon : 3,
						title : '提示'
					},function(index) {
						$layrow.remove();	
						layui.layer.close(index);
						countTopRows($, ['incontractfee','outcontractfee','prevrecordfee','currprevrecordfee','surplusoutcontractfee']);
			});			
		}).on('click', '.add-new-row', function() {
			addNewRow(this);
		}).on('click', '.add-sub-row', function() {
			addSubRow(this);
		}).on('click', '.del-sub-row', function() {
			deleteSubRow(this);
		}).on('keyup','.decimal', function() {
			var val = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
			var val2 = val.replace(/[^0-9.]/g, "");
					this.value = val2;
		}).on('blur','.layui-row .contract-money input[type=text]', function() {
					var $tr = $(this).parents('tr');
					var type, id;
					type = $(this).prop('class')
							.replace('layui-input', '')
							.replace('decimal', '')
							.trim();					
					id = $tr.prop("id");
					if(!$(this).hasClass("typeNames")){
						arabiaToCN(this,1);
					}
					incontractfee(type,$tr);		
					parentGroup($, type, id);
		}).on('blur','.layui-row input.subNames',function(){
			var $this = $(this);
			var $itemNameSubInputs = $this.parents('div.layui-row').find('input.itemNameSub');
			$itemNameSubInputs.val(this.value);																
		});	
	}
	
	var  listModeDataBind = function($){	
		var listModeData = [{subItemListName:'',contractsNumber:0,measurementUnit:'',contractPrice:0,sumPrice:0 }];	
		
		var $table = $('#list-mode').find('tbody'),$sumListModeInput= $('#sumListMode');$table.empty();
		var template = $('#list-mode-tr').html();		
		$table.on('click','.add-row',function(){						
			var $row = $(this).parents('tr');
			var rowId = parseInt($row.find('.label').text())+1;				
			var newRowHtml = template.format(rowId);
			var $newRow = $(newRowHtml);
			$row.after($newRow);
		
			var newIndex = $newRow.index(); 
			$table.find('tr:gt('+newIndex+')').each(function(){
				var $row = $(this);
				var rowId= parseInt($row.find('.label').text())+1;
				$row.find('.label').text(rowId).end().find('input[type=hidden]').val(rowId);					
			});
			
		}).on('click','.del-row',function(){						
			
			var $row = $(this).parents('tr');
			var index = $row.index()-1;
			$row.remove();
			
			$table.find('tr:gt('+index+')').each(function(){
				var $row = $(this);
				var rowId= parseInt($row.find('.label').text())-1;
				$row.find('.label').text(rowId).end().find('input[type=hidden]').val(rowId);					
			});
			
			$sumListModeInput.val($table.find('input[type=text].sumPrice').inputTotal());
			
			
		}).on('keyup','.decimal', function() {
			var val = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
			var val2 = val.replace(/[^0-9.]/g,"");
			this.value = val2;
		}).on('keyup','.integer', function() {
			var val = this.value.replace(/^(\-)*([1-9]\d*)\.(\d\d).*$/,'$2');
			var val2 = val.replace(/[^0-9.]/g,"");
			this.value = val2;
		}).on('blur','.contractsNumber,.contractPrice,.sumPrice', function() {
			var $tr = $(this).parents('tr');
			if(!$(this).hasClass("contractsNumber")){
				arabiaToCN(this,1); 
			}
			if(!$(this).hasClass("sumPrice")){
				sumPrice($tr);
				$sumListModeInput.val($table.find('input[type=text].sumPrice').inputTotal());
				$('#payment-node').find('tbody').find('tr').each(function(){
					var $tr = $(this);
					payAmount($tr);
				});
			}
		});		
		
		for(var i=0,j=listModeData.length;i<j;i++){
			var html=[],rowId=i+1;
			var item = listModeData[i];
			var rowHtml = template.format(rowId,item.subItemListName,item.measurementUnit,item.contractsNumber,item.contractPrice,item.sumPrice);
			var $rowHtml = $(rowHtml);
			if(i==0){
				$rowHtml.find('.del-row').remove();
			}
			sumPrice($rowHtml);
			$table.append($rowHtml);
		}
		$sumListModeInput.val($table.find('input[type=text].sumPrice').inputTotal());
		
		function sumPrice($tr){
			$contractsNumber = $tr.find('.contractsNumber'),
			$contractPrice = $tr.find('.contractPrice'),
			$sumPrice = $tr.find('.sumPrice');
			var number = $contractsNumber.val().toFloat(),price = $contractPrice.val().toFloat(),sumPrice = number * price;			
			$sumPrice.val(sumPrice.toMoney());	
		}	
	}
	

var paymentNodeDataBind = function($){	
	var paymentNodeData=[{nodeName:'',nodePayProportion:0,payAmount:0}];
	var templateHtml=$('#payment-node-tr').html();
	var $table=$('#payment-node').find('tbody');$table.empty();
	$table.on('click','.add-row',function(){						
		var $row = $(this).parents('tr');
		var rowId= parseInt($row.find('.label').text())+1;
		var paymentNodeTr = templateHtml.format(rowId,'',0,0);		
		var $newRow = $(paymentNodeTr);
		$row.after($newRow);
	
		var newIndex = $newRow.index(); 
		$table.find('tr:gt('+newIndex+')').each(function(){
			var $row = $(this);
			var rowId= parseInt($row.find('.label').text())+1;
			$row.find('.label').text(rowId).end().find('input[type=hidden]').val(rowId);					
		});
					
	}).on('click','.del-row',function(){						
		var $row = $(this).parents('tr');
		if($table.find('tr').length==1){
			return layer.msg('至少需保留一个子项', {icon: 1});
		}
		layui.layer.confirm('确定删除？', {
					icon : 3,
					title : '提示'
				},function(index) {
				
					var i = $row.index()-1
					$table.find('tr:gt('+i+')').each(function(){
						var $row = $(this);
						var rowId= parseInt($row.find('.label').text())-1;
						$row.find('.label').text(rowId).end().find('input[type=hidden]').val(rowId);					
					});	
					$row.remove();	
					layui.layer.close(index);
		});		
	}).on('keyup','.decimal', function() {
		var val = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
		var val2 = val.replace(/[^0-9.]/g,"");
		this.value = val2;
	}).on('blur','.nodePayProportion,.payAmount',function() {
		var $tr = $(this).parents('tr');
		if($(this).hasClass("payAmount")){
			arabiaToCN(this,1);
		}
		if($(this).hasClass("nodePayProportion")){
			payAmount($tr);
		}
	});
	
	for(var i=0,j = paymentNodeData.length;i<j;i++){
		var html=[],rowId=i+1;
		var item = paymentNodeData[i];
		var paymentNodeTr = templateHtml.format(rowId,item.nodeName,item.nodePayProportion,item.payAmount);		
		var $row = $(paymentNodeTr);
		if(i==0){
			$row.find('.del-row').remove();										
		}
		$table.append($row);
		payAmount($row);
	}	
}

	var $ = layui.$;
	function payAmount($tr){
		var $ = layui.$;
		var proportion = $tr.find('.nodePayProportion').val().toFloat()/100;
		var total = $('#sumListMode').val().toFloat();
		var amount = total * proportion;
		$tr.find('.payAmount').val(amount.toMoney());
	}

	var uploadRender = function(id, upload, $) {
		upload
				.render({
					elem : '#' + id + '-upload-more',
					url : basePath + '/otherCot/uploadAtt/',
					data : {
						types : id
					},
					multiple : true,
					accept : 'file',
					acceptMime : 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',
					before : function(obj) {
						layer.load();
					},
					done : function(res) {
						if (res.code > 0) {
							layer.closeAll('loading');
							return layer.msg(res.msg, {
								icon : 7
							});
						}
						if (res.entity != null && res.entity.length > 0) {
							for ( var i in res.entity) {
								var preProject = res.entity[i];
								var arr = preProject.split("|");
								var imgSrc = "";
								var suffix = arr[1].substring(arr[1]
										.lastIndexOf(".") + 1, arr[1].length);
								if (suffix == 'jpg' || suffix == 'png') {
									imgSrc = "${fileHttpPre}/" + arr[3];
								} else {
									imgSrc = "${ctx}/resources/images/"
											+ suffix + ".jpg";
								}
								$('#' + id + '-upload-more-list')
										.append(
												'<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''
														+ "${fileHttpPre}"
														+ arr[3]
														+ '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
														+ arr[2]
														+ '\')";>删除</a></div><p>'
														+ arr[1]
														+ '</p><input type="hidden" value="'+preProject+'" id="fileAtt_'+arr[2]+'" name="fileAtts'+id+'" ></input></div>');
							}
						}
					},
					allDone : function(obj) {
						layer.closeAll('loading');
					},
					error : function() {
						layer.closeAll('loading');
						layer.msg("上传失败，请稍后再试~", {
							icon : 7
						});
					}
				});
	}
	//删除文件
	function del(index) {
		layui.$("#fileAtt_" + index).remove();
		layui.$("#upload_img_" + index).remove();
	}

	//根据url查看文件
	function showImg(url) {
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	
	//根据其他项目名称带出其他项目需要的字段
	function getOtherCotByProId(id) {
		var $ = layui.$, form = layui.form
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/otherCot/getOtherCotSaByProCode",//路径  
			data : {
				"proCodeAndCodes" : id
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if (result.flag == true) {
					if(result.otherCotDomain == null){
						return;
					}
					//其他合同名称带出其他合同基础信息
					$("#contractId")
						.val( result.otherCotDomain.otherCotName);//其他合同名称
					$("#id_proName")
						.val( result.otherCotDomain.proName);//项目名称
					$("#id_proCode")
						.val( result.otherCotDomain.proCode);//项目编号
					if (result.otherCotDomain.orgAreaName != null) {
						$("#id_regionalCompany").val(
								result.otherCotDomain.orgAreaName);//区域公司
						$("#areaId").val(
								result.otherCotDomain.hrOrgAreaId);//区域公司id
					} else {
						$("#id_regionalCompany").val( "暂时为空不可编辑");//区域公司
					}					
					if (result.otherCotDomain.orgProName != null) {
						$("#id_projectCompany").val(
								result.otherCotDomain.orgProName);//项目公司
						$("#compId").val(
								result.otherCotDomain.hrOrgProId);//项目公司id											
					} else {
						$("#id_projectCompany").val( "暂时为空不可编辑");//项目公司
		
					}
					$("#id_ImplementingBody").val(
							result.otherCotDomain.carryOrg);//实施机构
					$("#id_projectLeader").val(
							result.otherCotDomain.proLeader);//项目负责人
					$("#id_projectAddress").val(
							result.otherCotDomain.sgCityName);//项目地址
					$("#sgCityId").val(
							result.otherCotDomain.sgCityId);//项目城市id
					$("#id_contractUnitName").val(
							result.otherCotDomain.sgCoopName);//合同单位名称
					$("#sgCoopId").val(
							result.otherCotDomain.sgCoopId);//合同单位id
					
					//其他合同名称带出项目代付费信息或项目前期费信息
					var feeTypeName,$contractPriceInfo = $('.contract-price-info');
					if(result.otherCotDomain.cotType=='32'){
						$('#id_feeTypes').val('政府代付费');
						feeTypeName = '政府代付费';
						$contractPriceInfo.find('legend').text('项目代付费信息 >');
					}else if(result.otherCotDomain.cotType=='33'){
						$('#id_feeTypes').val('项目前期费');
						feeTypeName = '项目前期费';
						$contractPriceInfo.find('legend').text('项目前期费信息 >');
					}
					$('#cotTypeId').val(result.otherCotDomain.cotType);
					
					$('#incontractfee').val(result.otherCotDomain.outOrInnerAmount);
					$('#outcontractfee').val(result.otherCotDomain.outCotAmount);
					$('#prevrecordfee').val(result.otherCotDomain.beforeAmount);
					$('#currprevrecordfee').val(result.otherCotDomain.addupAmount);   
					$('#surplusoutcontractfee').val(result.otherCotDomain.outRestAmount);
					
					if(!!feeTypeName==true){
						$contractPriceInfo.css('display','block');
						var $contractList = $('.contract-list'),
						layuiRowHtml = $('#layui-row').html();	
						$contractList.find(".layui-row").remove();
					
						if(result.selectDetailAndSubList.length>0){	
							var hash = {},subList=[];					
							for(var i = 0, j = result.selectDetailAndSubList.length; i < j; i++) {												
								var e = result.selectDetailAndSubList[i];						
								if(typeof(hash[e.cotSubId])=='undefined'){
									hash[e.cotSubId] = subList.length;							
									subList.push({
										subName:e.subName,
										cotSubId:e.cotSubId,
										list:[{
											subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
											costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,													
											incontractfee : e.outOrInnerAmount,
											outcontractfee : e.outCotAmount,
											prevrecordfee : e.beforeAmount,
											currprevrecordfee : e.addupAmount,
											surplusoutcontractfee : e.outRestAmount
									}]});							

								}else{								
									var index =  hash[e.cotSubId].toString().toInt();
									subList[index].list.push({
										subRowId : e.orderIdx.indexOf(',')!=-1?e.orderIdx.split(',')[1]:e.orderIdx,
										costType : e.typeName.indexOf(',')!=-1?e.typeName.split(',')[1]:e.typeName,
										incontractfee : e.outOrInnerAmount,
										outcontractfee : e.outCotAmount,
										prevrecordfee : e.beforeAmount,
										currprevrecordfee : e.addupAmount,
										surplusoutcontractfee : e.outRestAmount
									});						
								}						
							}
							
							for (var i = 0, j = subList.length; i < j; i++) {									
								var e = result.selectDetailAndSubList[i];
								var itemNameSub = subList[i].subName,subId = subList[i].cotSubId;
								var tempHtml = layuiRowHtml.format(subId,itemNameSub,feeTypeName);
								var $html = $(tempHtml);
								if(i==j-1){
									$html.find('tbody:last tr:gt('+j+')').remove();
								}
								
								subList[i].list.forEach(function(e) {
											var subRowId = e.subRowId;
											var costType = e.costType;
											var incontractfee = e.incontractfee.toString();
											var outcontractfee = e.outcontractfee.toString();
											var prevrecordfee = e.prevrecordfee.toString();
											var currprevrecordfee = e.currprevrecordfee.toString();
											var surplusoutcontractfee = e.surplusoutcontractfee.toString();
											
											var trid = subRowId.indexOf('.')!=-1?('tr[id="sub' + subId + 'Row-' + subRowId + '"]'):('tr[id="' + subId + 'Row-' + subRowId + '"]');
											var $row = $html.find(trid);
											
											if ($row.length == 1) {
												$row.find('input[type="hidden"]:eq(0)').val(subRowId);
												var $typeNames = $row.find('td:eq(1) input.typeNames');									
												if ($typeNames.val() == '') {						
													$typeNames.val(costType);								
													var $lastPrev = $typeNames.prevAll(':last');
													$lastPrev.text(costType);
												}												
												$row.find('td:eq(2) input').val(incontractfee);
												$row.find('td:eq(3) input').val(outcontractfee);
												$row.find('td:eq(4) input').val(prevrecordfee);
												$row.find('td:eq(5) input').val(currprevrecordfee);
												$row.find('td:eq(6) input').val(surplusoutcontractfee);
												
											} else {
												
												var arr = subRowId.split('.');
												var level = arr.length;
												if (level == 2) {									
													var id = "sub"+subId+"Row-"+subRowId;												
													var types = subRowId.split('.');        
											        var feeTypes = types[0],feeSmallTypes = types[0]+'.'+types[1];						        												
													var $trHtml = $($('#layui-row-tr').html().format(id,level,subRowId,subId,costType,feeTypes,feeSmallTypes,itemNameSub,incontractfee,outcontractfee,prevrecordfee
															,currprevrecordfee,surplusoutcontractfee));
													
													var pop = arr.pop();
													var parent = arr.length==1? subId + 'Row-' + arr[0]:"sub" + subId + "Row-" + arr.join('.');								
													var siblings = (parent.indexOf('sub')==-1?'sub':'') + parent + '.';								
													var $parent = $html.find("tr[id='" + parent + "']");
													var $siblings = $html.find("tr[id^='" + siblings + "']");								
													var siblingslen = $siblings.length;							
													setReadonly($parent);
													
													if (siblingslen > 0) {
														var $last = $($siblings[siblingslen - 1]);
														var lastId = $last.prop('id');
														if (lastId.split('.').pop() == pop - 1) {										
																								
															$last.after($trHtml);													 
														}
													} else if ($parent.length == 1 && pop == '1') {
														
														$parent.after($trHtml);
													}
																				
												}
											}
								});
								$contractList.append($html);
							}																		
						}

					}else{
						$contractPriceInfo.css('display','none');
					}
					
					//其他合同名称带出合同费用清单
					var $table = $('#list-mode').find('tbody'),$sumListModeInput= $('#sumListMode');
					var template = $('#list-mode-tr').html();
					$('#list-mode').find('tbody').empty();
					
					if(result.selectOtherCotLists.length>0){
						for(var i=0,j=result.selectOtherCotLists.length;i<j;i++){
							var html=[],rowId=i+1;
							var item = result.selectOtherCotLists[i];
							var rowHtml = template.format(item.showIdx,item.subName,item.subUnit,item.cotNums,item.cotUnitPrice,item.cotSumPrice);
							var $rowHtml = $(rowHtml);
							if(i==0){
								$rowHtml.find('.del-row').remove();
							}
							$contractsNumber = $rowHtml.find('.contractsNumber'),
							$contractPrice = $rowHtml.find('.contractPrice'),
							$sumPrice = $rowHtml.find('.sumPrice');
							var number = $contractsNumber.val().toFloat(),price = $contractPrice.val().toFloat(),sumPrice = number * price;			
							$sumPrice.val(sumPrice.toMoney());
							$table.append($rowHtml);
						}
						$sumListModeInput.val($table.find('input[type=text].sumPrice').inputTotal());
					}
					
					//其他合同名称带出其他合同的合同信息	
					$("#id_Contractconstructionperiodyear").val(
							result.otherCotDomain.periodYears);//合同工期（年）
					
					$("#id_Contractoperationperiodyear").val(
							result.otherCotDomain.periodDays);//合同工期(天)
					
					//合同开工日期									
					if (result.otherCotDomain.beginBuildDate != null) {
						var beginBuildDate = layui.util.toDateString(result.otherCotDomain.beginBuildDate,"yyyy-MM-dd");
						
						$("#id_contractCommencementDate").val(beginBuildDate);
					} else {
						$("#id_contractCommencementDate").val( "合同开工日期为空");
		
					}
					//计算合同竣工日期
					if (result.otherCotDomain.endBuildDate != null) {
						var endBuildDate = layui.util.toDateString(result.otherCotDomain.endBuildDate,"yyyy-MM-dd");					
						$("#id_contractCompletionDate").val(endBuildDate);
					} else {
						$("#id_contractCompletionDate").val( "合同竣工日期为空");
		
					}
					$("#id_cotSettMode").html('');
				      	var strCotSettModeBuffer = ""; 
				      	if(result.otherCotDomain.cotSettMode != null){//合同结算模式
				        	if(result.otherCotDomain.cotSettMode=='1'){
				        		strCotSettModeBuffer+= '<option value='+1+' selected>固定总价合同</option>';
				        		strCotSettModeBuffer+= '<option value='+2+'>综合单价合同</option>';
				        		strCotSettModeBuffer+= '<option value='+3+'>组合模式</option>';
				        	}else if(result.otherCotDomain.cotSettMode=='2'){
				        		strCotSettModeBuffer+= '<option value='+2+' selected>综合单价合同</option>';
				        		strCotSettModeBuffer+= '<option value='+1+'>固定总价合同</option>';
				        		strCotSettModeBuffer+= '<option value='+3+'>组合模式</option>';
				        	}else if(result.otherCotDomain.cotSettMode=='3'){
				        		strCotSettModeBuffer+= '<option value='+3+' selected>组合模式</option>';
				        		strCotSettModeBuffer+= '<option value='+1+'>固定总价合同</option>';
				        		strCotSettModeBuffer+= '<option value='+2+'>综合单价合同</option>';
				        	}else{
				        		strCotSettModeBuffer+= '<option value='+9+'>请选择</option>';
				        	}
				      }
				    $("#id_cotSettMode").append(strCotSettModeBuffer);
					$("#id_standardMemo").html(result.otherCotDomain.standardMemo);//乙方完工标准
					
					//其他合同名称带出付款节点
					var templateHtml=$('#payment-node-tr').html();
					var $table=$('#payment-node').find('tbody');
					$('#payment-node').find('tbody').empty();
					
					if(result.selectOtherCotNodeLists.length>0){
						for(var i=0,j = result.selectOtherCotNodeLists.length;i<j;i++){
							var html=[],rowId=i+1;
							var item = result.selectOtherCotNodeLists[i];
							var paymentNodeTr = templateHtml.format(item.orderIdx,item.nodeName,item.payRate,item.payAmount);		
							var $row = $(paymentNodeTr);
							if(i==0){
								$row.find('.del-row').remove();										
							}
							$table.append($row);
							var proportion = $row.find('.nodePayProportion').val().toFloat()/100;
							var total = $('#sumListMode').val().toFloat();
							var amount = total * proportion;
							$row.find('.payAmount').val(amount.toMoney());
						}		
					}
						
					//其他合同名称带出其他合同的附件信息数据
					var otherCotAtt = result.selectOtherCotAttLists;//合同的附件信息集合
					
					$(".layui-upload-list").each(function(){
						var id = $(this).attr("id");
						$("#"+id).html('');
					});
					if(otherCotAtt.length > 0){
						layui.$.each(otherCotAtt, function(i,item){
							var imgSrc = "";
							var suffix = item.fileSuffix;
							if(suffix == '.jpg' || suffix == '.png'){
								imgSrc = "${fileHttpPre}/"+item.filePath;
							}else{
								imgSrc = "${ctx}/resources/images/"+suffix.substring(1)+".jpg";
							}
							$('#'+item.types+'-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+item.id+'"><img src="'+imgSrc+'" title="'+ item.fileName +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+item.filePath +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+item.id+'\')";>删除</a></div><p>'+item.fileName+'</p><input type="hidden" value="'+item.types+"|"+item.fileName+item.fileSuffix+"|"+item.id+"|"+item.filePath+'" id="fileAtt_'+item.id+'" name="fileAtts'+item.types+'" ></input></div> ');
	                    });
					}					
					form.render();
				}
			}
		});
	}

	//合同开工日期
	function checkValueVerifyBeginBuildDate(laydate, $) {
		var Data_id_contractCommencementDate = laydate
			.render({
				elem : '#id_contractCommencementDate',
				trigger : 'click',
				done : function(value, date) {
					var valueContractconstructionperioddays = $(
							"#id_Contractoperationperiodyear").attr("value");//合同工期（天）
					var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
					if (rgx.test(valueContractconstructionperioddays)) {//'请输入正确数字，且保留两位小数！'
						var nextday1 = addDate(value,
								valueContractconstructionperioddays);
						$("#id_contractCompletionDate")
								.val( nextday1);//合同竣工日期
					}
				}
			});
	}

	/**
	 * [dateAddDays 从某个日期增加n天后的日期]
	 * @param  {[string]} dateTemp  [日期字符串]
	 * @param  {[int]} days [增加的天数]
	 * @return {[string]}[增加n天后的日期字符串]
	 */
	 function addDate(dateTemp, days) {
	    var nDate = new Date(dateTemp);
	    var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
	    var rDate = new Date(millSeconds);
	    var year = rDate.getFullYear();
	    var month = rDate.getMonth() + 1;
	    month = month < 10 ? "0"+month : month;
	    var date = rDate.getDate();
	    date = date < 10 ? "0"+date : date;
	    return (year + "-" + month + "-" + date);
	}
	// 请输入正确数字，且保留两位小数！
	function checkValueverifyNumber2(obj) {
		var $ = layui.$, form = layui.form
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(obj.value);// true 
		if (boolrgx) {
			if (obj.id == "id_Contractconstructionperiodyear") {//合同工期(年)
				$("#id_Contractoperationperiodyear").val(
						obj.value * 365);//合同工期(天)
			}
		} else {
			obj.value =0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
	}
	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat1(str) {
		var $ = layui.$, form = layui.form
		if (str.value == '' || str.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(str.value);// true 
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			return false;
		}
	}
	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat2(str) {
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(str);// true 
		if (boolrgx) {
			return true;
		} else {
			return false;
		}
	}
	
	function deleteSubRow(t) {
		var $ = layui.$;
		layui.layer.confirm('确定删除？',{
							icon : 3,
							title : '提示'
						},
						function(index) {
							var $tr = $(t).parents('tr');
							var id = $tr.prop("id");
							var level = $tr.attr("level");
							var arr = id.split('.');
							arr.pop();
							var prefix = arr.join('.') + '.';
							
							var $waitRemove = $('tr[id="`"], tr[id^="`."]'
									.replace(/`/g, id));
							if (level == '2') {
								var waitRemoveLast = $waitRemove[$waitRemove.length - 1];
								var waitRemoveLastId = $(waitRemoveLast).prop("id");
								var waitRemoveLastIndex = null;
								
								$("tr[id^='" + prefix + "']").each(function(index) {
											if (this.id == waitRemoveLastId) {
												waitRemoveLastIndex = index;
												return false;
											}
								});
								
								$("tr[id^='" + prefix + "']:gt(" + waitRemoveLastIndex + ")")
										.each(
												function(index) {
													if ($(this).attr('level') == '3') {
														var temp = this.id
																.split('-');
														var numList = temp[1]
																.split('.');
														numList[1] = parseInt(numList[1]) - 1;
														var subRowId = numList
																.join('.');
														var nextId = temp[0]
																+ '-'
																+ subRowId;
																												
														var types = subRowId.split('.');        
								                        var feeSmallTypes=types[0]+'.'+types[1];
								                		
								                        $(this).attr('id', nextId).find(".label").text(subRowId)
								                		.end().find("input[type=hidden]:first").val(subRowId)
								                		.end().find("input[type=hidden].feeSmallTypes").val(feeSmallTypes);	
								                		
								                		
													}
												});
							}
							$waitRemove.remove();

							var $subRows = $("tr[id^='" + prefix + "'][level="+ level + "]");
							var rowId = prefix.split('-')[1];
							$subRows.each(function(index) {
								var sortid = index + 1
								var subRowId = rowId + sortid;
								var nextId = prefix + sortid;
								
				                var types = subRowId.split('.');        
				                var feeSmallTypes = types[0]+'.'+types[1];                
				                $(this).attr('id', nextId).find(".label").text(subRowId)
				                .end().find("input[type=hidden]:first").val(subRowId)
				                .end().find("input[type=hidden].feeSmallTypes").val(feeSmallTypes);															

							});
							
							if($subRows.length==0){
								var $parentRow = null;
								if (arr.length == 1) {
									$parentRow = $('#' + arr[0].replace('sub', ''));
								}
								if (arr.length == 2) {
									$parentRow = $('[id="' + arr.join('.')+'"]');
								}
								removeReadonly($parentRow)
							}
							parentGroup($, 'incontractfee', id);
							
							layui.layer.close(index);
						});
	}

	
	function removeReadonly($t) {
		if ($t) {
			$t.find('input[type=text].incontractfee').removeProp('readonly').attr('lay-verify','required|floatNumber');
		}
	}

	function setReadonly($t) {
		if ($t) {
			$t.find('input[type=text].incontractfee').prop('readonly', true).removeAttr('lay-verify');
		}
	}
	//新增三级行
	function addSubRow(t) {
		var $ = layui.$;
		var $parentRow = $(t).parents('tr');
		var level = parseInt($parentRow.attr('level')) + 1;
		var parentId = $parentRow.attr('id');
		var subParentId =  parentId + '.';
		var $subRows = $("tr[id^='" + subParentId + "']");
		var $lastRow = ($subRows.length > 0) ? $("tr[id^='" + subParentId + "']:last") : $parentRow;
		var arr = $lastRow.attr('id').split('.');

		var count = $subRows.length > 0 ? arr[parentId.split('.').length] - 0 : 0;
		var subId = subParentId.replace(/^sub(.*)Row.*$/, '$1');
		count++;
		var nextId = subParentId + count;
		var subRowId = nextId.split('-')[1];
		var types = subRowId.split('.');        
        var feeTypes = types[0],feeSmallTypes = types[0]+'.'+types[1];
        var itemNameSub = $lastRow.find('.itemNameSub').val();
        
        
		var $rowHtml = $($('#layui-row-tr-add').html().format(nextId,level,subRowId,subId,'',feeTypes,feeSmallTypes,itemNameSub,'0','0','0','0'));
		$rowHtml.find("td:last").html('<button type="button" class="layui-btn layui-btn-sm del-sub-row"   ><i class="layui-icon">&#xe640;</i></button>');
		if($subRows.length == 0){
			setReadonly($parentRow);
		}
		$lastRow.after($rowHtml);
		layui.form.render();
	}
	//新增二级行
	function addNewRow(t) {
		var $ = layui.$;
		var $parentRow = $(t).parents('tr');
		var level = parseInt($parentRow.attr('level')) + 1;
		var parentId = $parentRow.attr('id');
		var subParentId = parentId.indexOf('sub') == 0 ? parentId + '.' : 'sub'
				+ parentId + '.';
		var $subRows = $("tr[id^='" + subParentId + "']");
		var $lastRow = ($subRows.length > 0) ? $("tr[id^='" + subParentId + "']:last") : $parentRow;
		var arr = $lastRow.attr('id').split('.');

		var count = $subRows.length > 0 ? arr[parentId.split('.').length] - 0 : 0;
		var subId = subParentId.replace(/^sub(.*)Row.*$/, '$1');
		count++;
		var nextId = subParentId + count;
		var subRowId = nextId.split('-')[1];
		var html = [],types = subRowId.split('.');        
        var feeTypes = types[0],feeSmallTypes = types[0]+'.'+types[1];
        var itemNameSub = $lastRow.find('.itemNameSub').val();
        
		html.push('<tr id='+nextId + '  level='+level+' >');
		html.push('<td><span class="label" >' + subRowId + '</span><input type="hidden" value="' + subRowId + '" name="orderIdxs" /><input type="hidden" value="' + subId + '" name="contractSubId" /></td>');
		html.push('<td><input type="text" lay-verify="required" maxlength="50" value="" onblur="getOtherCotPreRecordAmount(this);" autocomplete="off" class="layui-input typeNames" name="typeNames" />');
		html.push('<input type="hidden" value="'+feeTypes+'" name="feeTypes"  class="feeTypes" />');
		html.push('<input type="hidden" value="'+feeSmallTypes+'" name="feeSmallTypes" class="feeSmallTypes" />');
		html.push('<input type="hidden" value="'+itemNameSub+'" name="itemNameSub" class="itemNameSub" />');
		html.push('</td><td><input type="text" name="outOrInnerAmounts" value="" lay-verify="required|floatNumber" maxlength="13" autocomplete="off" class="layui-input decimal incontractfee" /></td>');		
		html.push('<td><input type="text" name="outCotAmounts" value="0" readonly style="border:0px" class="layui-input  outcontractfee" /></td>');		
		html.push('<td><input type="text" name="beforeAmounts" value="" readonly style="border:0px" class="layui-input  prevrecordfee" /></td>');	
		html.push('<td><input type="text" name="addupAmounts" value="" readonly style="border:0px" class="layui-input  currprevrecordfee" /></td>');
		html.push('<td><input type="text" name="outRestAmounts" value="" readonly style="border:0px" class="layui-input  surplusoutcontractfee" /></td>');
		html.push('<td>');
		html.push('<button type="button" class="layui-btn layui-btn-sm del-sub-row"   ><i class="layui-icon">&#xe640;</i></button>');
		if (nextId.split('.').length < 3) {
			html.push('<button type="button" class="layui-btn layui-btn-sm add-sub-row" ><i class="layui-icon">&#xe654;</i></button>');
		}
		html.push('</td>');
		html.push('</tr>');

		var medalHtml = html.join('');
		$lastRow.after(medalHtml);
		setReadonly($parentRow);
		layui.form.render();
	}
	//通过费用类型和子项名称获取该项目前期已录金额
	function getOtherCotPreRecordAmount(obj){
		var $ = layui.$;		
		var typeName = obj.value;
		var proCodeAndCodes = $("#add_select_proId").val();
		var $tr = $(obj).parents('tr');
		var subName = $tr.find('.itemNameSub').val();
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/otherCot/getOtherCotPreRecordAmount",//路径  
			data : {
				"proCodeAndCodes" : proCodeAndCodes,
				"typeName" : typeName,
				"subName" : subName
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if (result.flag == true) {
					if(result.otherCotDomain!=null){
						//取得前期已录金额且开累已录金额等于前期已入金额
						var beforeAmount = result.otherCotDomain.addupAmountTotal;
						var outOrInnerAmount = $tr.find('.incontractfee').val();
						if(outOrInnerAmount==''||outOrInnerAmount==null){
							$tr.find('.incontractfee').val(0);
							outOrInnerAmount = 0;
						}
						$tr.find('.prevrecordfee').val(beforeAmount);
						$tr.find('.currprevrecordfee').val(parseFloat(beforeAmount)+parseFloat(outOrInnerAmount));
						var addupAmount = $tr.find('.currprevrecordfee').val();
						var outRestAmount = $tr.find('.outcontractfee').val()- addupAmount;
						$tr.find('.surplusoutcontractfee').val(outRestAmount);
					}else{
						$tr.find('.incontractfee').val(0);
						$tr.find('.prevrecordfee').val(0);
						$tr.find('.currprevrecordfee').val(0);
						$tr.find('.surplusoutcontractfee').val(0);
					}
				}
			}
		});
	}
</script>